<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="main.css">

<%@ page import="ejb.TargetFacadeEJBRemote" %> 
<%@ page import="model.Target" %>

<title>Apply for Merchant</title>
<%
String targetid = request.getParameter("targetID");

out.println("<input type=\"hidden\" id=\"target\" value=\""+targetid+"\"/>");		
out.println("<h2>Merchant Application: </h2>");
%>
<script type="text/javascript">
function pass(){
	var patrn2=/^(\w?|\s?|\.|\\|\,|\?|:){1,500}$/;
    if((document.getElementById("applyform").value)==""){
        alert("reason is empty!");
        return false;
    }
    else if(!patrn2.exec(document.getElementById("applyform").value)){
    	alert("reason format error or too long! its length should not be longer than 500");
    	return false;
    }else{
	window.location.href="TargetServlet?targetid="+document.getElementById("target").value+"&applyform="+document.getElementById("applyform").value;
    }
}
</script>
</head>

<% String name=(String)session.getAttribute("username");

if(name==null){
    out.print("Please login first! redirecting to Login...");
    response.setHeader("Refresh","1;URL=login.jsp");
}
else{
%>

<body>

<form action="ApplyServlet" name="apply" method="get">
	<table width="900">
	  	<tr><td>Please justify your reasons:</td><td>
	  	<tr><td><textarea name="apply_reason" cols=80 rows=15 id="applyform"></textarea></td><td>	
   	   	<tr><td><input type="button" onclick="pass()" value="Submit" >
   	   	<input type="button" onclick="javascript:location.href='Home'" value="Back to Home"/></td></tr>
   	   	
   	</table>
   	
</form>

</body>

<% } %>

</html>

